/* Add file extension to _dst, if _src does not have it, or copy as is */
char* ExtAdd(_dst, _src, _count, _ext)
char		*_dst;
char		*_src;
unsigned	_count;
char		*_ext;	/* ".BMP" */
{
	strncpy(_dst, _src, _count);
	if (_ext && !index(_dst,'.')) strcat(_dst,_ext);
	return _dst;
}



/* Substitute file extension if exists or simply add like ExtAdd */
char* ExtSub(_dst, _src, _count, _ext)
char		*_dst;
char		*_src;
unsigned	_count;
char		*_ext;	/* ".BMP" */
{
	char	*extdot;
	
	strncpy(_dst, _src, _count);
	
	if (_ext)
	{
		if (extdot = index(_dst,'.')) *extdot = 0;
		strcat(_dst,_ext);
	}
	return _dst;
}



char* Ptr2Str(_ptr,_str)
char* _ptr;
char* _str;
{
	return _ptr ? _ptr : (_str ? _str : "");
}




trouble(_text1,_text2)
char *_text1;
char *_text2;
{
	/*
		if (errno) perror("CRT error:");
	*/
	
 	printf	( "\nError: %s %s"
		, Ptr2Str(_text1,"unknown")
		, Ptr2Str(_text2,0)
		);
	puts("\007");
	exit(1);
}


NotSupported(_text)
char	*_text;
{
	trouble(_text, "is not supported");
}



ChkMax(_int, _max, _name)
int	_int;
int	_max;
char*	_name;
{
	char	text[0x100];
	
	if (_int  > _max)
	{
		sprintf(text,"%s larger than %d", _name, _max);
		NotSupported(text);
	}
}


Chk64K(_uint, _name)
unsigned	*_uint;
char		*_name;
{
	char	text[0x100];
	
	if (*++_uint)
	{
		sprintf(text,"%s larger than 64K", _name);
		NotSupported(text);
	}
}
